package com.ecarx.library_base.base_widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.ecarx.library_base.R;

public class ItemCommenView extends LinearLayout {
    private TextView mLeftText,mSubTitle;
    private ImageView mRightImg;
    public ItemCommenView(Context context) {
        this(context,null);
    }

    public ItemCommenView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.item_view, this);
        mLeftText =  findViewById(R.id.left_text);
        mSubTitle = findViewById(R.id.subTitle);
        mRightImg = findViewById(R.id.img_right);
    }

    public void setInfo(String leftString,int rightImgRes){
        mLeftText.setText(leftString);
        if(rightImgRes>0){
            mRightImg.setImageResource(rightImgRes);
            mRightImg.setVisibility(VISIBLE);
        }else {
            mRightImg.setVisibility(GONE);
        }
    }

    public void setLeftTextColor(ColorStateList color){
        mLeftText.setTextColor(color);
    }

    public void setSubTitle(String subTitle){
        mSubTitle.setText(subTitle);
    }

    public String getSubTitle(){
        return mSubTitle.getText().toString();
    }

    public void setInfo(int leftString,int rightImgRes){
        mLeftText.setText(leftString);
        if(rightImgRes>0){
            mRightImg.setImageResource(rightImgRes);
            mRightImg.setVisibility(VISIBLE);
        }else {
            mRightImg.setVisibility(GONE);
        }
    }
}
